<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="标题">
      <el-input v-model="form.title" />
    </el-form-item>
    <el-form-item label="是否公开">
      <el-checkbox v-model="form.is_select" size="large" />
    </el-form-item>
    <el-form-item label="内容">
      <el-input v-model="form.content" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">发布</el-button>
      <el-button @click="resetFn">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script setup>
import { reactive } from "vue";
import http from "@/utils/http.js";

// do not use same name with ref
const form = reactive({
  titel: "",
  is_select: false,
  content: "",
});

const onSubmit = () => {
  http
    .request({
      url: "/posts",
      method: "post",
      data: {
        title: form.title,
        content: form.content,
        status: form.is_select,
      },
    })
    .then((res) => {
      console.log(res.data);
      ElMessage.success("发布成功");
    });
};
function resetFn() {
  form.title = "";
  form.is_select = false;
  form.content = "";
}
</script>
<style lang="css" scoped></style>
